/**
 * Created by huangxuehua on 2017/11/24.
 */
//$(".goBack").click(function(){
//    window.history.go(-1)
//});
var xpHome = new Vue({
    el:'#app',
    data:{
        userInfo:{},//用户信息
        IsJoin:{} //是否参加返利活动
    },
    methods:{
        goNextPage:function(pageType){ //进入订单页面
             var tUrl = "my_center_detail/indent/indent.html?flag="+pageType;
            // pageType 全部订单 all  //待付款 unpayed  //待发货 unshipped  //待收货 unchecked  //待评价 uncomment
            window.location.href = tUrl;
        },
        goAfterSale:function(){//售后
            window.location.href="my_center_detail/after_sale_detail.html";
        },
        goDaiYan:function(){//我的代言
            window.location.href="./my_center_detail/my_daiYan.html";
            window.localStorage.setItem("isUserJoin",JSON.stringify(xpHome.IsJoin))
        },
        goCoupon:function(){//我的优惠券
            window.location.href="coupon/coupon.html";
        },
        goAddress:function(){//收货地址
            window.location.href="./my_center_detail/my_address.html?flag=mycenter";
        },
        goCollect:function(){//收藏
            window.location.href="./my_center_detail/collect.html";
        },
       getUserInfo:function(){
           //var data ={
           //    "access_token":userInfo.access_token,
           //}
           $.ajax({
               url:nUrls.getUserInfo,
               type:"POST",
               //data:data,
               success:function(data){
                   //console.log("++++")
                   var result = eval('('+data+')');
                   if(result && result.code == 200) {
                       xpHome.userInfo=result.data
                      //console.log("--result--",result)
                   }
               },
               error:function(){
                   console.log("获取用户信息失败")
               }
           })
       },
        getIsJoinInfo:function(){  //获取是否已经参加返利活动
            $.ajax({
                url:nUrls.getIsJoin,
                type:"POST",
                success:function(data){
                    var result = eval('(' + data + ')');
                    if (result && result.code == 200) {
                        xpHome.IsJoin=result
                        console.log("--xpHome.IsJoin--",xpHome.IsJoin.isJoin)
                    }
                },
                error: function (msg) {
                    console.log("服务器内部错误",msg);
                }
            })
        },
        goErWeiMa:function(){  //去分享页面，二维码页面
            if(xpHome.IsJoin.isJoin==1){
                window.location.href=serverUrl+"?r=marketing/sharereb/test#menu-image"
            }else{
                window.alert = function(name){
                    var iframe = document.createElement("IFRAME");
                    iframe.style.display="none";
                    iframe.setAttribute("src", 'data:text/plain,');
                    document.documentElement.appendChild(iframe);
                    window.frames[0].window.alert(name);
                    iframe.parentNode.removeChild(iframe);
                };
                alert('您尚未参加零元分享购活动！');

                return
            }
        },
        goOnLine:function(){  //断网刷新
            nUtils.onLine();
        }
    }
});

$(function(){
    xpHome.getUserInfo();
    xpHome.getIsJoinInfo();//是否参加返利活动
})
//底部菜单栏跳转
var tab = new auiTab({
    element:document.getElementById("footer"),
    index:3
},function(ret){
    if(ret){
        if(ret.index == 1){
            window.location.href = "../index.html";
        }else if(ret.index == 2){
                 window.location.href = "shop_cart.html";
            }else if(ret.index == 3){
                 window.location.href = "#";
            }
    }
});
